STM32 bare-metal crypto port (HASH / AES / PKA / RNG, DHUK, CCB)#10395
STM32 bare-metal crypto port (HASH / AES / PKA / RNG, DHUK, CCB)#10395dgarske wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new STM32 “bare-metal” crypto port flavor (WOLFSSL_STM32_BARE) that uses CMSIS device-header register access (no HAL/StdPeriph dependency) and wires it into wolfCrypt’s AES/HASH/RNG paths, plus a direct-register PKA implementation used by the existing STM32 PKA integration.
Changes:
- Add
WOLFSSL_STM32_BAREselection in settings to include only CMSIS device headers and auto-enable the no-lib RNG path. - Add per-family bare-metal clock-enable macros and HAL/PKA stand-in types to support a direct-register PKA driver.
- Add bare-metal AES (CRYP + TinyAES), HASH clock enable override, and bare PKA shims/driver, plus AES dispatcher updates in
aes.cand RNG clock-enable macro use inrandom.c.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
wolfssl/wolfcrypt/settings.h |
Adds WOLFSSL_STM32_BARE selection, CMSIS header includes, and mutual exclusion with CubeMX. |
wolfssl/wolfcrypt/port/st/stm32.h |
Adds BARE clock-enable macros, HASH ALGO defines for new IP, and PKA stand-in types. |
wolfcrypt/src/port/st/stm32.c |
Implements bare-metal AES (CRYP/TinyAES), HASH clock enable override, and bare-metal PKA shims/driver. |
wolfcrypt/src/aes.c |
Routes ECB/CBC/CTR and GCM-encrypt through the BARE STM32 implementation with SW fallback behavior. |
wolfcrypt/src/random.c |
Uses a per-family RNG clock-enable macro (for BARE) instead of a fixed RCC register bit. |
wolfcrypt/src/ecc.c |
Adjusts STM32 PKA guards so BARE uses SW ECDSA paths while still leveraging HW scalar mul. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
8058c8c to
22ee90e
Compare
|
Note #10307 seems to have broken AES CBC on STM32... I will put the fix into my new wolfSSL/wolfssl-examples-stm32#13 |
1c9091e to
3519503
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (1)
wolfcrypt/src/port/st/stm32.c:1
- After
wc_Stm32_Aes_DhukOp()completes, the unwrapped key remains resident in SAES key registers (KEYR) until overwritten by a later operation. If the platform threat model includes debug/privileged register reads or post-operation key scraping, consider explicitly clearing KEYR/CR state (or triggering any available peripheral key/CCF/error clear mechanism) before releasing the mutex. This is especially relevant because DHUK is explicitly about protecting keys at rest/in RAM.
/* stm32.c
965e81b to
2c8100c
Compare
0145fa0 to
b0ba9ce
Compare
|
Jenkins retest this please |
65fc021 to
9b9eb3e
Compare
Adds a direct-register STM32 hardware-crypto integration that needs zero HAL or StdPeriphLib, for wolfBoot / no-OS / FreeRTOS / TrustZone-NS use. Builds and is validated across ~27 STM32 families. Layered as the bare IP drivers, DHUK device-bound keys, and CCB hardware-protected ECDSA.
Features
WOLFSSL_STM32_BARE): direct-register AES (TinyAES / CRYP / SAES), HASH (classic and new-gen IP), RNG, and PKA (V1 and V2 layouts: ECDSA sign/verify and ECC scalar-mul). The same code drives both the bare path and the CubeMX/HAL path. On STM32C5, whose PKA exposes only the side-channel-protected ECC modes, ECDSA sign runs in hardware and verify in software.devIdto it, and run normal AES / GMAC / ECDSA - the working key is derived inside SAES and never enters software.wc_ecc_make_keyto provision,wc_ecc_sign_hashto sign) - no CCB-specific public API; both bare and CubeMX/HAL backends.New build options
WOLFSSL_STM32_BARE- bare-metal direct-register path (vsWOLFSSL_STM32_CUBEMX).STM32_CRYPTO,STM32_HASH,STM32_RNG,WOLFSSL_STM32_PKA(+WC_STM32_PKA_VERIFY_ONLY/WC_STM32_PKA_SIGN_ONLYfor verify-only or sign-only parts such as STM32C5),WOLFSSL_STM32_USE_SAES.WOLFSSL_DHUK+WOLF_CRYPTO_CB- DHUK crypto-callback device (WOLFSSL_STM32_DHUK_UNWRAPfor the optional exact-key import).WOLFSSL_STM32_CCB- CCB-protected ECDSA (requires DHUK + crypto-cb, STM32U3 or STM32C5 silicon).WOLFSSL_STM32U3,WOLFSSL_STM32C5, ...) select register layouts.Testing performed
STM32_Bare_Testharness (wolfcrypt_test+ benchmark), covering ~27 STM32 families: F2/F3/F4/F7, G0/G4, H5/H7/H7RS, L4/L5, U0/U3/U5, WB/WBA/WL, C0/C5, N6, and more. Latest sweep: all attached boards PASS.wc_ecc_make_key->wc_ecc_sign_hash->wc_ecc_verify_hash, scalar never in software.check-source-textclean.Known limitations / follow-up
Reference
Per-board chip-support matrix, build sizes, and benchmarks (companion examples branch): https://github.com/dgarske/wolfssl-examples-stm32/blob/stm32_bare/STM32_Bare_Test/README.md